/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Anthares
 */
@Entity
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Commande.findAll", query = "SELECT c FROM Commande c"),
    @NamedQuery(name = "Commande.findByComId", query = "SELECT c FROM Commande c WHERE c.comId = :comId"),
    @NamedQuery(name = "Commande.findByDateCommande", query = "SELECT c FROM Commande c WHERE c.dateCommande = :dateCommande"),
    @NamedQuery(name = "Commande.findByAccompte", query = "SELECT c FROM Commande c WHERE c.accompte = :accompte")})
public class Commande implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "COM_ID", nullable = false)
    private Integer comId;

    @Basic(optional = false)
    @NotNull
    @Column(name = "DATE_COMMANDE", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateCommande;

    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private double accompte;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "commande")
    private List<LigneCommande> ligneCommandeList;

    @JoinColumn(name = "CLIENT_ID", referencedColumnName = "CLIENT_ID", nullable = false)
    @ManyToOne(optional = false)
    private Client clientId;

    public Commande() {
    }

    public Commande(Integer comId) {
        this.comId = comId;
    }

    public Commande(Date dateCommande, double accompte) {
        this.dateCommande = dateCommande;
        this.accompte = accompte;
    }
    

    public Commande(Integer comId, Date dateCommande, double accompte) {
        this.comId = comId;
        this.dateCommande = dateCommande;
        this.accompte = accompte;
    }

    public Integer getComId() {
        return comId;
    }

    public void setComId(Integer comId) {
        this.comId = comId;
    }

    public Date getDateCommande() {
        return dateCommande;
    }

    public void setDateCommande(Date dateCommande) {
        this.dateCommande = dateCommande;
    }

    public double getAccompte() {
        return accompte;
    }

    public void setAccompte(double accompte) {
        this.accompte = accompte;
    }

    @XmlTransient
    public List<LigneCommande> getLigneCommandeList() {
        return ligneCommandeList;
    }

    public void setLigneCommandeList(List<LigneCommande> ligneCommandeList) {
        this.ligneCommandeList = ligneCommandeList;
    }

    public Client getClientId() {
        return clientId;
    }

    public void setClientId(Client clientId) {
        this.clientId = clientId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (comId != null ? comId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Commande)) {
            return false;
        }
        Commande other = (Commande) object;
        if ((this.comId == null && other.comId != null) || (this.comId != null && !this.comId.equals(other.comId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Model.Commande[ comId=" + comId + " ]";
    }
    
}
